package cn.bb.cn.bb.action;

import cn.bb.pojo.Person;
import cn.bb.service.IPersonService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
@Scope(value = "prototype")
@ParentPackage("struts-default")
public class PersonAction extends ActionSupport {
    @Autowired
    @Qualifier("personService")
    private IPersonService iPersonService;
    @Action(value = "person_list", results = {
            @Result(location = "/list.jsp")
    })
    public String list(){
        List<Person> list = iPersonService.search();
        HttpServletRequest httpServletRequest = ServletActionContext.getRequest();
        httpServletRequest.setAttribute("list",list);
        return SUCCESS;
    }
    public IPersonService getiPersonService() {
        return iPersonService;
    }

    public void setiPersonService(IPersonService iPersonService) {
        this.iPersonService = iPersonService;
    }
}
